﻿using AutoMapper;
using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Domain.yjb;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.settingCommand;
using MyMES.Writer.API.FileNlog;

namespace MyMES.Writer.API.Application.CommendHandlers.settingCommand
{
    public class AddgttCommandHandlers : IRequestHandler<AddgttCommand, APIResult<ProductionTasks>>
    {
        private readonly IBaseRepository<ProductionTasks> accreop;
        private readonly IMapper mapper;
        private readonly Nolgs nolgs;

        public AddgttCommandHandlers(IBaseRepository<ProductionTasks> accreop,IMapper mapper,Nolgs nolgs)
        {
            this.accreop = accreop;
            this.mapper = mapper;
            this.nolgs = nolgs;
        }
        /// <summary>
        /// 工序添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<ProductionTasks>> Handle(AddgttCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<ProductionTasks> result = new APIResult<ProductionTasks>();
                result.Code = APIEnum.添加成功;
                result.Msg = "添加成功";
                var model = mapper.Map<ProductionTasks>(request);
                string sql = "insert into ProductionTasks(ProductionTaskId,TaskName, Status, Resource, StartTime, EndTime,IsDelete) values(@ProductionTaskId,@TaskName, @Status, @Resource, @StartTime, @EndTime,@IsDelete)";
                await accreop.Insert(model, sql);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
